<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>天气案例-监视属性</title>
    <script src="../../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h1>今天天气 {{info}}</h1>
        <button @click="changeWeather">切换天气</button>
        <!-- <button @click="isHot = !isHot"> 切换天气</button> -->
    </div> 


    <script>
        Vue.config.productionTip = false;
        const vm = new Vue({
            el: '#root',
            data:{ 
                isHot: true,
            },
            computed: {
                info(){
                    return this.isHot ? '热' : '爽'
                }
            },
            methods: {
                changeWeather(){
                    this.isHot = !this.isHot
                }
            },
           /*  watch:{
                // 1
                isHot :{
                    // 初始化时让handler调用一下
                    // immediate: true,
                    // handler? isHot发生改变时
                    handler(newValue, oldValue){
                        console.log('isHot改变了w1', newValue, oldValue)
                    }
                }
                // 2
                info :{
                    // immediate: true,
                    handler(newValue, oldValue){
                        console.log('isHot改变了w2', newValue, oldValue)
                    }
                }
            } */
        })
        vm.$watch('isHot',{
            // immediate: true,
            handler(newValue, oldValue){
                console.log('isHot改变了w3', newValue, oldValue)
            }
        })
    </script>

</body>
</html>